package com.horay.statemachiedemo.multi.guard;

import com.horay.statemachiedemo.multi.enums.ComplexState;
import com.horay.statemachiedemo.multi.event.ComplexEvent;
import com.horay.statemachiedemo.multi.model.Form;
import lombok.extern.slf4j.Slf4j;
import org.springframework.statemachine.StateContext;
import org.springframework.statemachine.guard.Guard;
import org.springframework.util.StringUtils;

/**
 * Class description
 *
 * @author heyingcheng
 * @date 2020/10/23
 */
@Slf4j
public class ComplexDealChoiceGuard implements Guard<ComplexState, ComplexEvent> {

    @Override
    public boolean evaluate(StateContext<ComplexState, ComplexEvent> context) {
        log.info("ComplexDealChoiceGuard!!!!!!!!!!!!!");
        Form form = context.getMessage().getHeaders().get(Form.class.getName(), Form.class);
        if (StringUtils.isEmpty(form.getFormName()) || (form.getFormName().indexOf("坏") > -1)) {
            return false;
        } else {
            return true;
        }
    }

}
